home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _fa801cacb799e675114307382f23a9bc < prev    next >
Encoding:
Text File  |  2002-06-17  |  23.4 KB  |  846 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec C:\p4view\Apps\ActivePerl\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.     if 0;
  17.  
  18. use warnings;
  19. use strict;
  20.  
  21. # make sure creat()s are neither too much nor too little
  22. INIT { eval { umask(0077) } }   # doubtless someone has no mask
  23.  
  24. (my $pager = <<'/../') =~ s/\s*\z//;
  25. more /e
  26. /../
  27. my @pagers = ();
  28. push @pagers, $pager if -x $pager;
  29.  
  30. (my $bindir = <<'/../') =~ s/\s*\z//;
  31. C:\p4view\Apps\ActivePerl\MSI\data\ActivePerl\Perl\bin
  32. /../
  33.  
  34.  
  35. use Fcntl;    # for sysopen
  36. use Getopt::Std;
  37. use Config '%Config';
  38. use File::Spec::Functions qw(catfile splitdir);
  39.  
  40. #
  41. # Perldoc revision #1 -- look up a piece of documentation in .pod format that
  42. # is embedded in the perl installation tree.
  43. #
  44. # This is not to be confused with Tom Christiansen's perlman, which is a
  45. # man replacement, written in perl. This perldoc is strictly for reading
  46. # the perl manuals, though it too is written in perl.
  47. # Massive security and correctness patches applied to this
  48. # noisome program by Tom Christiansen Sat Mar 11 15:22:33 MST 2000 
  49.  
  50. if (@ARGV<1) {
  51.     my $me = $0;        # Editing $0 is unportable
  52.     $me =~ s,.*/,,;
  53.     die <<EOF;
  54. Usage: $me [-h] [-r] [-i] [-v] [-t] [-u] [-m] [-n program] [-l] [-F] [-X] PageName|ModuleName|ProgramName
  55.        $me -f PerlFunc
  56.        $me -q FAQKeywords
  57.  
  58. The -h option prints more help.  Also try "perldoc perldoc" to get
  59. acquainted with the system.
  60. EOF
  61. }
  62.  
  63. my @global_found = ();
  64. my $global_target = "";
  65.  
  66. my $Is_VMS = $^O eq 'VMS';
  67. my $Is_MSWin32 = $^O eq 'MSWin32';
  68. my $Is_Dos = $^O eq 'dos';
  69. my $Is_OS2 = $^O eq 'os2';
  70.  
  71. sub usage{
  72.     warn "@_\n" if @_;
  73.     # Erase evidence of previous errors (if any), so exit status is simple.
  74.     $! = 0;
  75.     die <<EOF;
  76. perldoc [options] PageName|ModuleName|ProgramName...
  77. perldoc [options] -f BuiltinFunction
  78. perldoc [options] -q FAQRegex
  79.  
  80. Options:
  81.     -h   Display this help message
  82.     -r   Recursive search (slow)
  83.     -i   Ignore case
  84.     -t   Display pod using pod2text instead of pod2man and nroff
  85.              (-t is the default on win32)
  86.     -u     Display unformatted pod text
  87.     -m   Display module's file in its entirety
  88.     -n   Specify replacement for nroff
  89.     -l   Display the module's file name
  90.     -F   Arguments are file names, not modules
  91.     -v     Verbosely describe what's going on
  92.     -X     use index if present (looks for pod.idx at $Config{archlib})
  93.     -q   Search the text of questions (not answers) in perlfaq[1-9]
  94.     -U     Run in insecure mode (superuser only)
  95.  
  96. PageName|ModuleName...
  97.          is the name of a piece of documentation that you want to look at. You
  98.          may either give a descriptive name of the page (as in the case of
  99.          `perlfunc') the name of a module, either like `Term::Info',
  100.          `Term/Info', the partial name of a module, like `info', or
  101.          `makemaker', or the name of a program, like `perldoc'.
  102.  
  103. BuiltinFunction
  104.          is the name of a perl function.  Will extract documentation from
  105.          `perlfunc'.
  106.  
  107. FAQRegex
  108.          is a regex. Will search perlfaq[1-9] for and extract any
  109.          questions that match.
  110.  
  111. Any switches in the PERLDOC environment variable will be used before the
  112. command line arguments.  The optional pod index file contains a list of
  113. filenames, one per line.
  114.  
  115. EOF
  116. }
  117.  
  118. if (defined $ENV{"PERLDOC"}) {
  119.     require Text::ParseWords;
  120.     unshift(@ARGV, Text::ParseWords::shellwords($ENV{"PERLDOC"}));
  121. }
  122.  
  123. use vars qw( $opt_m $opt_h $opt_t $opt_l $opt_u $opt_v $opt_r $opt_i $opt_F $opt_f $opt_X $opt_q $opt_n $opt_U );
  124.  
  125. getopts("mhtluvriFf:Xq:n:U") || usage;
  126.  
  127. usage if $opt_h;
  128.  
  129. # refuse to run if we should be tainting and aren't
  130. # (but regular users deserve protection too, though!)
  131. if (!($Is_VMS || $Is_MSWin32 || $Is_Dos || $Is_OS2) && ($> == 0 || $< == 0)
  132.      && !am_taint_checking()) 
  133. {{
  134.     if ($opt_U) {
  135.         my $id = eval { getpwnam("nobody") };
  136.            $id = eval { getpwnam("nouser") } unless defined $id;
  137.            $id = -2 unless defined $id;
  138.         eval {
  139.             $> = $id;  # must do this one first!
  140.             $< = $id;
  141.         };
  142.         last if !$@ && $< && $>;
  143.     }
  144.     die "Superuser must not run $0 without security audit and taint checks.\n";
  145. }}
  146.  
  147. $opt_n = "nroff" if !$opt_n;
  148.  
  149. my $podidx;
  150. if ($opt_X) {
  151.     $podidx = "$Config{'archlib'}/pod.idx";
  152.     $podidx = "" unless -f $podidx && -r _ && -M _ <= 7;
  153. }
  154.  
  155. if ((my $opts = do{ no warnings; $opt_t + $opt_u + $opt_m + $opt_l }) > 1) {
  156.     usage("only one of -t, -u, -m or -l")
  157. }
  158. elsif ($Is_MSWin32
  159.        || $Is_Dos
  160.        || !($ENV{TERM} && $ENV{TERM} !~ /dumb|emacs|none|unknown/i))
  161. {
  162.     $opt_t = 1 unless $opts;
  163. }
  164.  
  165. if ($opt_t) { require Pod::Text; import Pod::Text; }
  166.  
  167. my @pages;
  168. if ($opt_f) {
  169.     @pages = ("perlfunc");
  170. }
  171. elsif ($opt_q) {
  172.     @pages = ("perlfaq1" .. "perlfaq9");
  173. }
  174. else {
  175.     @pages = @ARGV;
  176. }
  177.  
  178. # Does this look like a module or extension directory?
  179. if (-f "Makefile.PL") {
  180.  
  181.     # Add ., lib to @INC (if they exist)
  182.     eval q{ use lib qw(. lib); 1; } or die;
  183.  
  184.     # don't add if superuser
  185.     if ($< && $> && -f "blib") {   # don't be looking too hard now!
  186.     eval q{ use blib; 1 };
  187.     warn $@ if $@ && $opt_v;
  188.     }
  189. }
  190.  
  191. sub containspod {
  192.     my($file, $readit) = @_;
  193.     return 1 if !$readit && $file =~ /\.pod\z/i;
  194.     local($_);
  195.     open(TEST,"<", $file)     or die "Can't open $file: $!";
  196.     while (<TEST>) {
  197.     if (/^=head/) {
  198.         close(TEST)     or die "Can't close $file: $!";
  199.         return 1;
  200.     }
  201.     }
  202.     close(TEST)         or die "Can't close $file: $!";
  203.     return 0;
  204. }
  205.  
  206. sub minus_f_nocase {
  207.      my($dir,$file) = @_;
  208.      my $path = catfile($dir,$file);
  209.      return $path if -f $path and -r _;
  210.      if (!$opt_i or $Is_VMS or $Is_MSWin32 or $Is_Dos or $^O eq 'os2') {
  211.         # on a case-forgiving file system or if case is important
  212.     # that is it all we can do
  213.     warn "Ignored $path: unreadable\n" if -f _;
  214.     return '';
  215.      }
  216.      local *DIR;
  217.      # this is completely wicked.  don't mess with $", and if 
  218.      # you do, don't assume / is the dirsep!
  219.      local($")="/";
  220.      my @p = ($dir);
  221.      my($p,$cip);
  222.      foreach $p (splitdir $file){
  223.     my $try = catfile @p, $p;
  224.     stat $try;
  225.      if (-d _) {
  226.          push @p, $p;
  227.         if ( $p eq $global_target) {
  228.         my $tmp_path = catfile @p;
  229.         my $path_f = 0;
  230.         for (@global_found) {
  231.             $path_f = 1 if $_ eq $tmp_path;
  232.         }
  233.         push (@global_found, $tmp_path) unless $path_f;
  234.         print STDERR "Found as @p but directory\n" if $opt_v;
  235.         }
  236.      }
  237.     elsif (-f _ && -r _) {
  238.          return $try;
  239.      }
  240.     elsif (-f _) {
  241.         warn "Ignored $try: unreadable\n";
  242.      }
  243.     elsif (-d "@p") {
  244.          my $found=0;
  245.          my $lcp = lc $p;
  246.          opendir DIR, "@p"         or die "opendir @p: $!";
  247.          while ($cip=readdir(DIR)) {
  248.          if (lc $cip eq $lcp){
  249.              $found++;
  250.              last;
  251.          }
  252.          }
  253.          closedir DIR        or die "closedir @p: $!";
  254.          return "" unless $found;
  255.          push @p, $cip;
  256.          return "@p" if -f "@p" and -r _;
  257.         warn "Ignored @p: unreadable\n" if -f _;
  258.      }
  259.      }
  260.      return "";
  261. }
  262.  
  263.  
  264. sub check_file {
  265.     my($dir,$file) = @_;
  266.     return "" if length $dir and not -d $dir;
  267.     if ($opt_m) {
  268.     return minus_f_nocase($dir,$file);
  269.     }
  270.     else {
  271.     my $path = minus_f_nocase($dir,$file);
  272.         return $path if length $path and containspod($path);
  273.     }
  274.     return "";
  275. }
  276.  
  277.  
  278. sub searchfor {
  279.     my($recurse,$s,@dirs) = @_;
  280.     $s =~ s!::!/!g;
  281.     $s = VMS::Filespec::unixify($s) if $Is_VMS;
  282.     return $s if -f $s && containspod($s);
  283.     printf STDERR "Looking for $s in @dirs\n" if $opt_v;
  284.     my $ret;
  285.     my $i;
  286.     my $dir;
  287.     $global_target = (splitdir $s)[-1];   # XXX: why not use File::Basename?
  288.     for ($i=0; $i<@dirs; $i++) {
  289.     $dir = $dirs[$i];
  290.     ($dir = VMS::Filespec::unixpath($dir)) =~ s!/\z!! if $Is_VMS;
  291.     if (       ( $ret = check_file $dir,"$s.pod")
  292.         or ( $ret = check_file $dir,"$s.pm")
  293.         or ( $ret = check_file $dir,$s)
  294.         or ( $Is_VMS and
  295.              $ret = check_file $dir,"$s.com")
  296.         or ( $^O eq 'os2' and
  297.              $ret = check_file $dir,"$s.cmd")
  298.         or ( ($Is_MSWin32 or $Is_Dos or $^O eq 'os2') and
  299.              $ret = check_file $dir,"$s.bat")
  300.         or ( $ret = check_file "$dir/pod","$s.pod")
  301.         or ( $ret = check_file "$dir/pod",$s)
  302.         or ( $ret = check_file "$dir/pods","$s.pod")
  303.         or ( $ret = check_file "$dir/pods",$s)
  304.     ) {
  305.         return $ret;
  306.     }
  307.  
  308.     if ($recurse) {
  309.         opendir(D,$dir)    or die "Can't opendir $dir: $!";
  310.         my @newdirs = map catfile($dir, $_), grep {
  311.         not /^\.\.?\z/s and
  312.         not /^auto\z/s  and   # save time! don't search auto dirs
  313.         -d  catfile($dir, $_)
  314.         } readdir D;
  315.         closedir(D)        or die "Can't closedir $dir: $!";
  316.         next unless @newdirs;
  317.         # what a wicked map!
  318.         @newdirs = map((s/\.dir\z//,$_)[1],@newdirs) if $Is_VMS;
  319.         print STDERR "Also looking in @newdirs\n" if $opt_v;
  320.         push(@dirs,@newdirs);
  321.     }
  322.     }
  323.     return ();
  324. }
  325.  
  326. sub filter_nroff {
  327.   my @data = split /\n{2,}/, shift;
  328.   shift @data while @data and $data[0] !~ /\S/; # Go to header
  329.   shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
  330.   pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
  331.                 # 28/Jan/99 perl 5.005, patch 53 1
  332.   join "\n\n", @data;
  333. }
  334.  
  335. sub printout {
  336.     my ($file, $tmp, $filter) = @_;
  337.     my $err;
  338.  
  339.     if ($opt_t) {
  340.     # why was this append?
  341.     sysopen(OUT, $tmp, O_WRONLY | O_EXCL | O_CREAT, 0600)
  342.         or die ("Can't open $tmp: $!");
  343.     Pod::Text->new()->parse_from_file($file,\*OUT);
  344.     close OUT   or die "can't close $tmp: $!";
  345.     }
  346.     elsif (not $opt_u) {
  347.     my $cmd = catfile($bindir, 'pod2man') . " --lax $file | $opt_n -man";
  348.     $cmd .= " | col -x" if $^O =~ /hpux/;
  349.     my $rslt = `$cmd`;
  350.     $rslt = filter_nroff($rslt) if $filter;
  351.     unless (($err = $?)) {
  352.         # why was this append?
  353.         sysopen(TMP, $tmp, O_WRONLY | O_EXCL | O_CREAT, 0600)
  354.         or die "Can't open $tmp: $!";
  355.         print TMP $rslt
  356.         or die "Can't print $tmp: $!";
  357.         close TMP
  358.         or die "Can't close $tmp: $!";
  359.     }
  360.     }
  361.     if ($opt_u or $err or -z $tmp) {  # XXX: race with -z
  362.     # why was this append?
  363.     sysopen(OUT, $tmp, O_WRONLY | O_EXCL | O_CREAT, 0600)
  364.         or die "Can't open $tmp: $!";
  365.     open(IN,"<", $file)   or die("Can't open $file: $!");
  366.     my $cut = 1;
  367.     local $_;
  368.     while (<IN>) {
  369.         $cut = $1 eq 'cut' if /^=(\w+)/;
  370.         next if $cut;
  371.         print OUT
  372.         or die "Can't print $tmp: $!";
  373.     }
  374.     close IN    or die "Can't close $file: $!";
  375.     close OUT   or die "Can't close $tmp: $!";
  376.     }
  377. }
  378.  
  379. sub page {
  380.     my ($tmp, $no_tty, @pagers) = @_;
  381.     if ($no_tty) {
  382.     open(TMP,"<", $tmp)     or die "Can't open $tmp: $!";
  383.     local $_;
  384.     while (<TMP>) {
  385.         print or die "Can't print to stdout: $!";
  386.     } 
  387.     close TMP        or die "Can't close while $tmp: $!";
  388.     }
  389.     else {
  390.     foreach my $pager (@pagers) {
  391.           if ($Is_VMS) {
  392.            last if system("$pager $tmp") == 0; # quoting prevents logical expansion
  393.           } else {
  394.         last if system("$pager \"$tmp\"") == 0;
  395.           }
  396.     }
  397.     }
  398. }
  399.  
  400. sub cleanup {
  401.     my @files = @_;
  402.     for (@files) {
  403.     if ($Is_VMS) { 
  404.         1 while unlink($_);    # XXX: expect failure
  405.     } else {
  406.         unlink($_);           # or die "Can't unlink $_: $!";
  407.     } 
  408.     }
  409. }
  410.  
  411. my @found;
  412. foreach (@pages) {
  413.     if ($podidx && open(PODIDX, $podidx)) {
  414.     my $searchfor = catfile split '::';
  415.     print STDERR "Searching for '$searchfor' in $podidx\n" if $opt_v;
  416.     local $_;
  417.     while (<PODIDX>) {
  418.         chomp;
  419.         push(@found, $_) if m,/$searchfor(?:\.(?:pod|pm))?\z,i;
  420.     }
  421.     close(PODIDX)        or die "Can't close $podidx: $!";
  422.     next;
  423.     }
  424.     print STDERR "Searching for $_\n" if $opt_v;
  425.     # We must look both in @INC for library modules and in $bindir
  426.     # for executables, like h2xs or perldoc itself.
  427.     my @searchdirs = ($bindir, @INC);
  428.     if ($opt_F) {
  429.     next unless -r;
  430.     push @found, $_ if $opt_m or containspod($_);
  431.     next;
  432.     }
  433.     unless ($opt_m) {
  434.     if ($Is_VMS) {
  435.         my($i,$trn);
  436.         for ($i = 0; $trn = $ENV{'DCL$PATH;'.$i}; $i++) {
  437.         push(@searchdirs,$trn);
  438.         }
  439.         push(@searchdirs,'perl_root:[lib.pod]')  # installed pods
  440.     }
  441.     else {
  442.         push(@searchdirs, grep(-d, split($Config{path_sep},
  443.                          $ENV{'PATH'})));
  444.     }
  445.     }
  446.     my @files = searchfor(0,$_,@searchdirs);
  447.     if (@files) {
  448.     print STDERR "Found as @files\n" if $opt_v;
  449.     }
  450.     else {
  451.     # no match, try recursive search
  452.     @searchdirs = grep(!/^\.\z/s,@INC);
  453.     @files= searchfor(1,$_,@searchdirs) if $opt_r;
  454.     if (@files) {
  455.         print STDERR "Loosely found as @files\n" if $opt_v;
  456.     }
  457.     else {
  458.         print STDERR "No documentation found for \"$_\".\n";
  459.         if (@global_found) {
  460.         print STDERR "However, try\n";
  461.         for my $dir (@global_found) {
  462.             opendir(DIR, $dir) or die "opendir $dir: $!";
  463.             while (my $file = readdir(DIR)) {
  464.             next if ($file =~ /^\./s);
  465.             $file =~ s/\.(pm|pod)\z//;  # XXX: badfs
  466.             print STDERR "\tperldoc $_\::$file\n";
  467.             }
  468.             closedir DIR    or die "closedir $dir: $!";
  469.         }
  470.         }
  471.     }
  472.     }
  473.     push(@found,@files);
  474. }
  475.  
  476. if (!@found) {
  477.     exit ($Is_VMS ? 98962 : 1);
  478. }
  479.  
  480. if ($opt_l) {
  481.     print join("\n", @found), "\n";
  482.     exit;
  483. }
  484.  
  485. my $lines = $ENV{LINES} || 24;
  486.  
  487. my $no_tty;
  488. if (! -t STDOUT) { $no_tty = 1 }
  489. END { close(STDOUT) || die "Can't close STDOUT: $!" }
  490.  
  491. # until here we could simply exit or die
  492. # now we create temporary files that we have to clean up
  493. # namely $tmp, $buffer
  494. # that's because you did it wrong, should be descriptor based --tchrist
  495.  
  496. my $tmp;
  497. my $buffer;
  498. if ($Is_MSWin32) {
  499.     $tmp = "$ENV{TEMP}\\perldoc1.$$";
  500.     $buffer = "$ENV{TEMP}\\perldoc1.b$$";
  501.     push @pagers, qw( more< less notepad );
  502.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  503.     for (@found) { s,/,\\,g }
  504. }
  505. elsif ($Is_VMS) {
  506.     $tmp = 'Sys$Scratch:perldoc.tmp1_'.$$;
  507.     $buffer = 'Sys$Scratch:perldoc.tmp1_b'.$$;
  508.     push @pagers, qw( most more less type/page );
  509. }
  510. elsif ($Is_Dos) {
  511.     $tmp = "$ENV{TEMP}/perldoc1.$$";
  512.     $buffer = "$ENV{TEMP}/perldoc1.b$$";
  513.     $tmp =~ tr!\\/!//!s;
  514.     $buffer =~ tr!\\/!//!s;
  515.     push @pagers, qw( less.exe more.com< );
  516.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  517. }
  518. else {
  519.     if ($^O eq 'os2') {
  520.       require POSIX;
  521.       $tmp = POSIX::tmpnam();
  522.       $buffer = POSIX::tmpnam();
  523.       unshift @pagers, 'less', 'cmd /c more <';
  524.     }
  525.     else {
  526.       # XXX: this is not secure, because it doesn't open it
  527.       ($tmp, $buffer) = eval { require POSIX } 
  528.         ? (POSIX::tmpnam(),    POSIX::tmpnam()     )
  529.         : ("/tmp/perldoc1.$$", "/tmp/perldoc1.b$$" );
  530.     }
  531.     push @pagers, qw( more less pg view cat );
  532.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  533. }
  534. unshift @pagers, $ENV{PERLDOC_PAGER} if $ENV{PERLDOC_PAGER};
  535.  
  536. # make sure cleanup called
  537. eval q{
  538.     sub END { cleanup($tmp, $buffer) } 
  539.     1;
  540. } || die;
  541.  
  542. # exit/die in a windows sighandler is dangerous, so let it do the
  543. # default thing, which is to exit
  544. eval q{ use sigtrap qw(die INT TERM HUP QUIT) } unless $^O eq 'MSWin32';
  545.  
  546. if ($opt_m) {
  547.     foreach my $pager (@pagers) {
  548.     if (system($pager, @found) == 0) {
  549.         exit;
  550.     }
  551.     }
  552.     if ($Is_VMS) { 
  553.     eval q{
  554.         use vmsish qw(status exit); 
  555.         exit $?;
  556.         1;
  557.     } or die;
  558.     }
  559.     exit(1);
  560. }
  561.  
  562. my @pod;
  563. if ($opt_f) {
  564.     my $perlfunc = shift @found;
  565.     open(PFUNC, "<", $perlfunc)
  566.     or die("Can't open $perlfunc: $!");
  567.  
  568.     # Functions like -r, -e, etc. are listed under `-X'.
  569.     my $search_string = ($opt_f =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/)
  570.             ? 'I<-X' : $opt_f ;
  571.  
  572.     # Skip introduction
  573.     local $_;
  574.     while (<PFUNC>) {
  575.     last if /^=head2 Alphabetical Listing of Perl Functions/;
  576.     }
  577.  
  578.     # Look for our function
  579.     my $found = 0;
  580.     my $inlist = 0;
  581.     while (<PFUNC>) {
  582.     if (/^=item\s+\Q$search_string\E\b/o)  {
  583.         $found = 1;
  584.     }
  585.     elsif (/^=item/) {
  586.         last if $found > 1 and not $inlist;
  587.     }
  588.     next unless $found;
  589.     if (/^=over/) {
  590.         ++$inlist;
  591.     }
  592.     elsif (/^=back/) {
  593.         --$inlist;
  594.     }
  595.     push @pod, $_;
  596.     ++$found if /^\w/;    # found descriptive text
  597.     }
  598.     if (!@pod) {
  599.     die "No documentation for perl function `$opt_f' found\n";
  600.     }
  601.     close PFUNC        or die "Can't open $perlfunc: $!";
  602. }
  603.  
  604. if ($opt_q) {
  605.     local @ARGV = @found;    # I'm lazy, sue me.
  606.     my $found = 0;
  607.     my %found_in;
  608.     my $rx = eval { qr/$opt_q/ } or die <<EOD;
  609. Invalid regular expression '$opt_q' given as -q pattern:
  610.   $@
  611. Did you mean \\Q$opt_q ?
  612.  
  613. EOD
  614.  
  615.     for (@found) { die "invalid file spec: $!" if /[<>|]/ } 
  616.     local $_;
  617.     while (<>) {
  618.     if (/^=head2\s+.*(?:$opt_q)/oi) {
  619.         $found = 1;
  620.         push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++;
  621.     }
  622.     elsif (/^=head2/) {
  623.         $found = 0;
  624.     }
  625.     next unless $found;
  626.     push @pod, $_;
  627.     }
  628.     if (!@pod) {
  629.     die("No documentation for perl FAQ keyword `$opt_q' found\n");
  630.     }
  631. }
  632.  
  633. my $filter;
  634.  
  635. if (@pod) {
  636.     sysopen(TMP, $buffer, O_WRONLY | O_EXCL | O_CREAT)
  637.     or die("Can't open $buffer: $!");
  638.     print TMP "=over 8\n\n";
  639.     print TMP @pod    or die "Can't print $buffer: $!";
  640.     print TMP "=back\n";
  641.     close TMP        or die "Can't close $buffer: $!";
  642.     @found = $buffer;
  643.     $filter = 1;
  644. }
  645.  
  646. foreach (@found) {
  647.     printout($_, $tmp, $filter);
  648. }
  649. page($tmp, $no_tty, @pagers);
  650.  
  651. exit;
  652.  
  653. sub is_tainted {
  654.     my $arg = shift;
  655.     my $nada = substr($arg, 0, 0);  # zero-length
  656.     local $@;  # preserve caller's version
  657.     eval { eval "# $nada" };
  658.     return length($@) != 0;
  659. }
  660.  
  661. sub am_taint_checking {
  662.     my($k,$v) = each %ENV;
  663.     return is_tainted($v);  
  664. }
  665.  
  666.  
  667. __END__
  668.  
  669. =head1 NAME
  670.  
  671. perldoc - Look up Perl documentation in pod format.
  672.  
  673. =head1 SYNOPSIS
  674.  
  675. B<perldoc> [B<-h>] [B<-v>] [B<-t>] [B<-u>] [B<-m>] [B<-l>] [B<-F>]  [B<-X>] PageName|ModuleName|ProgramName
  676.  
  677. B<perldoc> B<-f> BuiltinFunction
  678.  
  679. B<perldoc> B<-q> FAQ Keyword
  680.  
  681. =head1 DESCRIPTION
  682.  
  683. I<perldoc> looks up a piece of documentation in .pod format that is embedded
  684. in the perl installation tree or in a perl script, and displays it via
  685. C<pod2man | nroff -man | $PAGER>. (In addition, if running under HP-UX,
  686. C<col -x> will be used.) This is primarily used for the documentation for
  687. the perl library modules.
  688.  
  689. Your system may also have man pages installed for those modules, in
  690. which case you can probably just use the man(1) command.
  691.  
  692. =head1 OPTIONS
  693.  
  694. =over 5
  695.  
  696. =item B<-h> help
  697.  
  698. Prints out a brief help message.
  699.  
  700. =item B<-v> verbose
  701.  
  702. Describes search for the item in detail.
  703.  
  704. =item B<-t> text output
  705.  
  706. Display docs using plain text converter, instead of nroff. This may be faster,
  707. but it won't look as nice.
  708.  
  709. =item B<-u> unformatted
  710.  
  711. Find docs only; skip reformatting by pod2*
  712.  
  713. =item B<-m> module
  714.  
  715. Display the entire module: both code and unformatted pod documentation.
  716. This may be useful if the docs don't explain a function in the detail
  717. you need, and you'd like to inspect the code directly; perldoc will find
  718. the file for you and simply hand it off for display.
  719.  
  720. =item B<-l> file name only
  721.  
  722. Display the file name of the module found.
  723.  
  724. =item B<-F> file names
  725.  
  726. Consider arguments as file names, no search in directories will be performed.
  727.  
  728. =item B<-f> perlfunc
  729.  
  730. The B<-f> option followed by the name of a perl built in function will
  731. extract the documentation of this function from L<perlfunc>.
  732.  
  733. =item B<-q> perlfaq
  734.  
  735. The B<-q> option takes a regular expression as an argument.  It will search
  736. the question headings in perlfaq[1-9] and print the entries matching
  737. the regular expression.
  738.  
  739. =item B<-X> use an index if present
  740.  
  741. The B<-X> option looks for a entry whose basename matches the name given on the
  742. command line in the file C<$Config{archlib}/pod.idx>.  The pod.idx file should
  743. contain fully qualified filenames, one per line.
  744.  
  745. =item B<-U> run insecurely
  746.  
  747. Because B<perldoc> does not run properly tainted, and is known to
  748. have security issues, it will not normally execute as the superuser.
  749. If you use the B<-U> flag, it will do so, but only after setting
  750. the effective and real IDs to nobody's or nouser's account, or -2
  751. if unavailable.  If it cannot relinguish its privileges, it will not
  752. run.  
  753.  
  754. =item B<PageName|ModuleName|ProgramName>
  755.  
  756. The item you want to look up.  Nested modules (such as C<File::Basename>)
  757. are specified either as C<File::Basename> or C<File/Basename>.  You may also
  758. give a descriptive name of a page, such as C<perlfunc>. You may also give a
  759. partial or wrong-case name, such as "basename" for "File::Basename", but
  760. this will be slower, if there is more then one page with the same partial
  761. name, you will only get the first one.
  762.  
  763. =back
  764.  
  765. =head1 ENVIRONMENT
  766.  
  767. Any switches in the C<PERLDOC> environment variable will be used before the
  768. command line arguments.  C<perldoc> also searches directories
  769. specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not
  770. defined) and C<PATH> environment variables.
  771. (The latter is so that embedded pods for executables, such as
  772. C<perldoc> itself, are available.)  C<perldoc> will use, in order of
  773. preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or
  774. C<PAGER> before trying to find a pager on its own.  (C<MANPAGER> is not
  775. used if C<perldoc> was told to display plain text or unformatted pod.)
  776.  
  777. One useful value for C<PERLDOC_PAGER> is C<less -+C -E>.
  778.  
  779. =head1 VERSION
  780.  
  781. This is perldoc v2.03.
  782.  
  783. =head1 AUTHOR
  784.  
  785. Kenneth Albanowski <kjahds@kjahds.com>
  786.  
  787. Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>,
  788. and others.
  789.  
  790. =cut
  791.  
  792. #
  793. # Version 2.03: Sun Apr 23 16:56:34 BST 2000
  794. #    Hugo van der Sanden <hv@crypt0.demon.co.uk>
  795. #    don't die when 'use blib' fails
  796. # Version 2.02: Mon Mar 13 18:03:04 MST 2000
  797. #       Tom Christiansen <tchrist@perl.com>
  798. #    Added -U insecurity option
  799. # Version 2.01: Sat Mar 11 15:22:33 MST 2000 
  800. #       Tom Christiansen <tchrist@perl.com>, querulously.
  801. #       Security and correctness patches.
  802. #       What a twisted bit of distasteful spaghetti code.
  803. # Version 2.0: ????
  804. # Version 1.15: Tue Aug 24 01:50:20 EST 1999
  805. #       Charles Wilson <cwilson@ece.gatech.edu>
  806. #    changed /pod/ directory to /pods/ for cygwin
  807. #         to support cygwin/win32
  808. # Version 1.14: Wed Jul 15 01:50:20 EST 1998
  809. #       Robin Barker <rmb1@cise.npl.co.uk>
  810. #    -strict, -w cleanups
  811. # Version 1.13: Fri Feb 27 16:20:50 EST 1997
  812. #       Gurusamy Sarathy <gsar@activestate.com>
  813. #    -doc tweaks for -F and -X options
  814. # Version 1.12: Sat Apr 12 22:41:09 EST 1997
  815. #       Gurusamy Sarathy <gsar@activestate.com>
  816. #    -various fixes for win32
  817. # Version 1.11: Tue Dec 26 09:54:33 EST 1995
  818. #       Kenneth Albanowski <kjahds@kjahds.com>
  819. #   -added Charles Bailey's further VMS patches, and -u switch
  820. #   -added -t switch, with pod2text support
  821. #
  822. # Version 1.10: Thu Nov  9 07:23:47 EST 1995
  823. #        Kenneth Albanowski <kjahds@kjahds.com>
  824. #    -added VMS support
  825. #    -added better error recognition (on no found pages, just exit. On
  826. #     missing nroff/pod2man, just display raw pod.)
  827. #    -added recursive/case-insensitive matching (thanks, Andreas). This
  828. #     slows things down a bit, unfortunately. Give a precise name, and
  829. #     it'll run faster.
  830. #
  831. # Version 1.01:    Tue May 30 14:47:34 EDT 1995
  832. #        Andy Dougherty  <doughera@lafcol.lafayette.edu>
  833. #   -added pod documentation.
  834. #   -added PATH searching.
  835. #   -added searching pod/ subdirectory (mainly to pick up perlfunc.pod
  836. #    and friends.
  837. #
  838. #
  839. # TODO:
  840. #
  841. #    Cache directories read during sloppy match
  842.  
  843. __END__
  844. :endofperl
  845.